package scigest.core;

import java.net.URI;
import java.net.URISyntaxException;

import thredds.catalog.InvCatalogFactory;
import thredds.catalog.InvCatalogImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 *
 * A simple catalog checker to validate the XML generated
 * provide URI (such as http:// or file:/// as command line input)
 *
 * @author Feiyi Wang
 *
 */
public class CatalogChecker {

	public static void main(String[] args) throws URISyntaxException {

		final Logger logger = LoggerFactory.getLogger(CatalogChecker.class);

		if (args.length != 1) {
			logger.error("Usage: Need a URI to proceed!");
			System.exit(1);
		}

		URI catalogURI = new URI(args[0]);
		InvCatalogFactory factory = new InvCatalogFactory("default", true);
		InvCatalogImpl catalog = (InvCatalogImpl) factory.readXML( catalogURI);
		StringBuilder buff = new StringBuilder();
		if (!catalog.check( buff)) {
			   logger.error("Invalid catalog <'{}'> \n {}",
					   catalogURI, buff.toString());
		} else {
			logger.info("Good, no error found!");
		}

	}
}
